<template>
  <div id="app">

    <!-- 对应展示的组件内容 -->
    <keep-alive>
      <transition>
        <router-view></router-view>
      </transition>
    </keep-alive>

    <!-- 底部导航选项 -->
    <nav class="mui-bar kl-bar-tab"
         v-show="bottomDisplay">
      <router-link class="kl-tab-item"
                   to="/index">
        <span class="mui-icon mui-icon-home"></span>
        <span class="mui-tab-label">首页</span>
      </router-link>
      <router-link class="kl-tab-item"
                   to="/category">
        <span class="mui-icon mui-icon-extra mui-icon-extra-order"></span>
        <span class="mui-tab-label">分类</span>
      </router-link>
      <router-link class="kl-tab-item"
                   to="/cart">
        <span class="mui-icon mui-icon-extra mui-icon-extra-cart"><span class="mui-badge">{{ $store.getters.getBadge }}</span></span>
        <span class="mui-tab-label">购物车</span>
      </router-link>
      <router-link class="kl-tab-item"
                   to="/my">
        <span class="mui-icon mui-icon-contact"></span>
        <span class="mui-tab-label">我的</span>
      </router-link>
    </nav>
  </div>
</template>

<script>

export default {
  data () {
    return {
      bottomDisplay: true
    }
  },
  created () { // 防止页面刷新，搜索页`商品详情页显示底部导航栏
    this.bottomDisplay = this.$route.path !== '/search'
    this.bottomDisplay = !this.$route.path.includes('/goodsInfo')
  },
  methods: {

  },
  components: {

  },
  watch: {
    '$route.path': function (newVal) { // 监听路由地址的变化。如果是搜索页就不显示底部导航栏
      if (newVal === '/search') {
        this.bottomDisplay = false
      } else {
        this.bottomDisplay = true
      }
      if (newVal.includes('/goodsInfo')) {
        this.bottomDisplay = false
      } else {
        this.bottomDisplay = true
      }
    }
  }
}
</script>

<style lang='less'>
// @import "./less/index.less";
* {
  touch-action: pan-y; /* 解决谷歌浏览器滑动出现警告 */
}
// 页面切换动画的特效
.v-enter {
  opacity: 0;
  transform: translateY(100%);
}
.v-leave-to {
  opacity: 0;
  transform: translateY(-100%);
  position: absolute; /*解决动画从下往上的影响*/
}
.v-enter-active,
.v-leave-active {
  transition: all 0.3s ease;
}
body {
  background: white !important;
  height: 100%;
  padding-bottom: 50px;
  #app {
    // position: relative;
    width: 100%;
    height: 100%;
    min-width: 320px;
    max-width: 750px;
    margin: 0 auto;
    overflow-x: hidden; /*解决组件动画移动时带来的滚动条影响*/
    .mui-bar {
      .kl-active {
        color: @klcolor;
      }
    }
  }
}

// 底部导航栏样式覆盖
.kl-bar-tab {
  bottom: 0;
  display: table;
  width: 100%;
  height: 50px;
  padding: 0;
  table-layout: fixed;
  border-top: 0;
  border-bottom: 0;
  -webkit-touch-callout: none;
}
.mui-bar {
  position: fixed;
  z-index: 10;
  right: 0;
  left: 0;
  height: 44px;
  padding-right: 10px;
  padding-left: 10px;
  border-bottom: 0;
  background-color: #f7f7f7;
  -webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.85);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.85);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.kl-bar-tab .kl-tab-item {
  display: table-cell;
  overflow: hidden;
  width: 1%;
  height: 50px;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #929292;
}
.kl-bar-tab .kl-tab-item .mui-icon {
  top: 3px;
  width: 24px;
  height: 24px;
  padding-top: 0;
  padding-bottom: 0;
}
.mui-bar .mui-icon {
  font-size: 24px;
  position: relative;
  z-index: 20;
  padding-top: 10px;
  padding-bottom: 10px;
}
.kl-bar-tab .kl-tab-item .mui-icon ~ .mui-tab-label {
  font-size: 11px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kl-bar-tab .kl-tab-item.mui-active {
  color: #007aff;
}
</style>
